- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 888
Use bulk conversion in Write8BitColor #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|  | ||
| ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span; | ||
| var color = default(Rgba32); | ||
| PixelOperations<TPixel>.Instance.ToRgba32(Configuration.Default, quantizedColors, rgbColors); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the configuration that the memory allocator is derived from.
| using IMemoryOwner<Rgba32> rgbColorsBuffer = this.memoryAllocator.Allocate<Rgba32>(quantized.Palette.Length); | ||
| Span<Rgba32> rgbColors = rgbColorsBuffer.GetSpan(); | ||
|  | ||
| ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span; | ||
| var color = default(Rgba32); | ||
| PixelOperations<TPixel>.Instance.ToRgba32(Configuration.Default, quantizedColors, rgbColors); | ||
|  | ||
| // TODO: Use bulk conversion here for better perf | ||
| int idx = 0; | ||
| foreach (TPixel quantizedColor in quantizedColors) | ||
| foreach (Rgba32 color in rgbColors) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not something like:
PixelOperations<TPixel>.Instance.ToRgba32(Configuration.Default, quantizedColors, MemoryMarshal.Cast<byte, Rgba32>(colorPalette));
ref Span<uint> colorPaletteAsUInt= MemoryMarshal.Cast<byte, uint>(colorPalette);
for (int i =0;i<colorPaletteAsUInt;i++)
  colorPaletteAsUInt[i] = colorPaletteAsUInt[i] & 0xFFFFFF00;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tidy!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that will do, it just needs to be ToBgra instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which should be fast enough with the new shuffle intrinsics
| Codecov Report
 @@            Coverage Diff             @@
##           master    #1428      +/-   ##
==========================================
- Coverage   83.08%   83.08%   -0.01%     
==========================================
  Files         707      707              
  Lines       31839    31834       -5     
  Branches     3590     3590              
==========================================
- Hits        26454    26449       -5     
  Misses       4668     4668              
  Partials      717      717              
 Flags with carried forward coverage won't be shown. Click here to find out more. 
 Continue to review full report at Codecov. 
 | 
Use bulk conversion in Write8BitColor
Prerequisites
Description
Just a small improvement in writing 8 bit bitmaps with a palette: Converting the quantized colors to rgb is now done as bulk convert.